package com.sekla.design;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

@Slf4j(topic = "c.TestOrderPrint")
public class orderPrint {
    static ReentrantLock Lock = new ReentrantLock();
    static Condition notification = Lock.newCondition();
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            Lock.lock();
            try {
                notification.await();
                log.debug("1");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } finally {
                Lock.unlock();
            }
        });

        Thread t2 = new Thread(() -> {
            Lock.lock();
            try {
                log.debug("2");
                notification.signal();
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                Lock.unlock();
            }
        });

        t1.start();
        t2.start();
    }
}
